//
//  LKMineViewController.m
//  Mideleague_Agent
//
//  Created by Zhiwang on 2020/5/22.
//  Copyright © 2020 Zhiwang. All rights reserved.
//

#import "LKMineViewController.h"
#import "LKMineHeaderView.h"
#import "LKMIneListCell.h"
#import "LKRateSettingViewController.h"
#import "LKEmployeerManageViewController.h"
#import "LKUseHelpViewController.h"
#import "LKAboutUsViewController.h"
#import "LKFeedBackViewController.h"
#import "LKFeedBacklistViewController.h"
@interface LKMineViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)LKBaseTableview *tableView;

@property(nonatomic,strong)NSArray *titlesArray;
@property(nonatomic,strong)NSArray *picturesArray;
@property(nonatomic,assign)BOOL goList;
@end

@implementation LKMineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.goList = NO;
    [self getMyFeedBacklistData];
    
//    self.titlesArray = @[@[@"我的费率",@"员工管理",@"成为盟主"],@[@"使用帮助",@"意见反馈",@"关于我们",@"基本设置",@"退出登录"]];
//        self.picturesArray = @[@[@"mine_about",@"yuangongguanli",@"mine_huiyuan"],@[@"mine_help",@"mine_about",@"mine_about1",@"mine_Setting",@"mine_Setting"]];
        self.titlesArray = @[@[@"我的费率"],@[@"使用帮助",@"意见反馈",@"关于我们",@"退出登录"]];
        self.picturesArray = @[@[@"mine_about"],@[@"mine_help",@"mine_about",@"mine_about1",@"mine_Setting"]];
    [self createMytable];
    // Do any additional setup after loading the view.
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = NO;
    [self.navigationController setNavigationBarHidden:YES animated:animated];
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}
-(void)createMytable{
    self.tableView = [LKBaseTableview setTableviewWithFrame:CGRectZero style:UITableViewStyleGrouped registercellClasss:@[@"LKMIneListCell"]];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    [self.view addSubview:_tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(self.view).offset(0);
        make.bottom.equalTo(self.view).offset(-44);
    }];
       if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        // Fallback on earlier versions
    }
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.titlesArray.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    NSArray *titlesArray = self.titlesArray[section];
    return titlesArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    LKMIneListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKMIneListCell"];
    cell.pictureImageV.image = [UIImage imageNamed:self.picturesArray[indexPath.section][indexPath.row]];
    cell.mylabel.text = self.titlesArray[indexPath.section][indexPath.row];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 52.0f;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        LKMineHeaderView *header = [[[NSBundle mainBundle] loadNibNamed:@"LKMineHeaderView" owner:self options:nil] lastObject];
        header.names = [LKUserInforTool account].user_name;
        header.account = [NSString stringWithFormat:@"手机号：%@",[LKUserInforTool account].user_phone];
        header.backgroundColor = COLOR_HEX(0xFDF8F5);
        return header;
    }
    return [[UIView alloc] init];
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 274.f;
    }
    return 10.0f;

}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *footerView = [[UIView alloc] init];
    return footerView;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 1.0f;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            LKRateSettingViewController *rateSettingVc = [[LKRateSettingViewController alloc] init];
            rateSettingVc.isMineIn = YES;
//            rateSettingVc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:rateSettingVc animated:YES];
        }
        if (indexPath.row == 1) {
//            LKEmployeerManageViewController *managerVc = [[LKEmployeerManageViewController alloc] init];
//            [self.navigationController pushViewController:managerVc animated:YES];
        }

    }
    if (indexPath.section == 1) {
        if (indexPath.row == 0) {
            LKUseHelpViewController *helpVc = [[LKUseHelpViewController alloc] init];
//            helpVc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:helpVc animated:YES];
        }

    }
    if (indexPath.section == 1) {
        if (indexPath.row == 1) {
            if (self.goList) {
                LKFeedBacklistViewController *vc = [[LKFeedBacklistViewController alloc] init];
//                vc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:vc animated:YES];
            }else{
                LKFeedBackViewController *Vc = [[LKFeedBackViewController alloc] init];
//                Vc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:Vc animated:YES];
            }

        
        }

    }
    if (indexPath.section == 1) {
        if (indexPath.row == 2) {
            LKAboutUsViewController *Vc = [[LKAboutUsViewController alloc] init];
//            Vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:Vc animated:YES];
        }

    }
    if (indexPath.section == 1) {
        if (indexPath.row == 3) {
            [LKUserInforTool noAccount];
            [LKSwitchRootVcTool switchRootController];
        }

    }
}

/// 获取我的反馈数据列表
-(void)getMyFeedBacklistData{
    NSDictionary *param = @{};
//    [SVProgressHUD showWithStatus:@"加载中..."];
    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:MyFeedbackListUrl header:[LKUserInforTool account].token parameters:param progress:^(NSProgress * _Nullable progress) {
        
    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
        if ([responseObject[@"code"] isEqualToString:@"success"]) {
            NSArray *contentArray = responseObject[@"data"];
            if (contentArray.count != 0) {
                self.goList = YES;
            }else{
                self.goList = NO;
            }
        }else{
            [SVProgressHUD showInfoWithStatus:responseObject[@"msg"]];
        }

    } failure:^(NSString * _Nullable errorMessage) {
        
    }];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
